#!/usr/bin/env python
# encoding: utf-8
"""
@author: youfeng
@email: youfeng243@163.com
@license: Apache Licence
@file: redis_handler.py
@time: 2018/1/9 10:00
"""

import redis


# redis 操作接口
class RedisHandler(object):
    def __init__(self, host, port, password, db, max_connections):
        self.redis_client = redis.StrictRedis(host=host,
                                              port=port,
                                              password=password,
                                              db=db,
                                              max_connections=max_connections)

    def setex(self, name, time, value):
        return self.redis_client.setex(name, time, value)

    def set(self, name, value, ex=None, px=None, nx=False, xx=False):
        return self.redis_client.set(name, value, ex=ex, px=px, nx=nx, xx=xx)

    def get(self, name):
        return self.redis_client.get(name)

    def delete(self, key):
        return self.redis_client.delete(key)

    # 清空缓存
    def flushdb(self):
        self.redis_client.flushdb()
